package com.hongkzh.www.adv.controller;

import com.google.common.collect.Lists;
import com.hongkzh.www.adv.service.AdvService;
import com.hongkzh.www.adv.service.EnterpriseAdvService;
import com.hongkzh.www.adv.service.MediaService;
import com.hongkzh.www.conmon.ReqResponse;
import com.hongkzh.www.swagger.annotation.*;
import com.jfinal.core.Controller;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;

import java.util.List;

/**
 * @author martins
 */
@Api(tag = "mediaAdv", description = "自媒体广告")
public class MediaAdvController extends Controller {
    MediaService mediaService=new MediaService();

    @ApiOperation(url = "/v1/mediaAdv/getMainCarouselList", tag = "mediaAdv", httpMethod = "post",description = "获取自媒体主页轮播图列表")
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "{ imgSrc 图片地址 ,imgLinks 图片链接 imgRank 图片排序 background 背景  id 视频广告id carouselId 轮播图id}"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getMainCarouselList(){
        ReqResponse<List<Record>> r=new ReqResponse();
        List<Record>  record= mediaService.getCarouselList();
        r.setData(record);
        renderJson(r);
    }

    @ApiOperation(url = "/v1/mediaAdv/getMainAllCategoryList", tag = "mediaAdv", httpMethod = "post",description = "获取自媒体主页分类信息")

    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "{ imgSrc 图片地址 ,categoryId 分类id imgRank 图片排序 name 名称  }"),
                    @ResponseHeader(name="msg",description = "失败原因") })
    })
    public void getMainAllCategoryList(){

        ReqResponse<List<Record>> r=new ReqResponse();
        List<Record>  record= Lists.newArrayList();

            record= mediaService.AllCategoryList();

        r.setData(record);
        renderJson(r);
    }
    @ApiOperation(url = "/v1/mediaAdv/getMainTop10List", tag = "mediaAdv", httpMethod = "post",description = "获取自媒体主页top10列表")
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "{ coverImgSrc 图片地址 ,title 标题 , praiseCount 点赞总数 ,categoryName 分类名称  cityName 城市名称 , userId 用户id , id 视频id  }"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getMainTop10List(){
        ReqResponse<List<Record>> r=new ReqResponse();
        List<Record>  record= mediaService.getTop10List();
        r.setData(record);
        renderJson(r);
    }




    @ApiOperation(url = "/v1/mediaAdv/getMainHotAdvList", tag = "mediaAdv", httpMethod = "post",description = "获取自媒体主页人气分页信息")

    @Params({
            @Param(name = "pageNumber", description = "页码", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "totalRow 总行数  pageNumber第几页 firstPage 是否第一页 lastPage 是否最后一页 totalPage 总页数 pageSize每页条数  list[{   id 视频id coverImgSrc 图片地址   title 标题 categoryName 分类名称  praiseCount 点赞数 rewardCount 奖励数  cityName 城市名称   advType 1数据 2 广告 vedioLength 视频长度 type 类型  1自媒体 2企业广告3城市广告4传统文化 }]"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getMainHotAdvList(){
        int pageNumber=getParaToInt("pageNumber");
        ReqResponse<Page<Record>> r=new ReqResponse();
        Page<Record> record= mediaService.getHotAdvList(pageNumber);
        r.setData(record);
        renderJson(r);
    }
    @ApiOperation(url = "/v1/mediaAdv/getMainNearbyAdvList", tag = "mediaAdv", httpMethod = "post",description = "获取自媒体主页附近分页信息")

    @Params({
            @Param(name = "latitude", description = "纬度", required = true, dataType = "string"),
            @Param(name = "longitude", description = "经度", required = true, dataType = "string"),
            @Param(name = "pageNumber", description = "页码", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "totalRow 总行数  pageNumber第几页 firstPage 是否第一页 lastPage 是否最后一页 totalPage 总页数 pageSize每页条数  list[{id 视频id coverImgSrc 图片地址 coverImgWidth封面宽 coverImgHeight封面高  title 标题 categoryName 分类名称  praiseCount 点赞数 rewardCount 奖励数    distance 距离   advType 1数据 2 广告 vedioLength 视频长度 type 类型  1自媒体 2企业广告3城市广告4传统文化  }]"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getMainNearbyAdvList(){
        double latitude=Double.parseDouble(getPara("latitude"));
        double longitude=Double.parseDouble(getPara("longitude"));
        int pageNumber=getParaToInt("pageNumber");
        ReqResponse<Page<Record>> r=new ReqResponse();

        Page<Record> record= mediaService.getNearbyAdvList(latitude,longitude,pageNumber);
        r.setData(record);
        renderJson(r);
    }

/*
    @ApiOperation(url = "/v1/mediaAdv/getCirclesList", tag = "mediaAdv", httpMethod = "post",description = "获取主页圈子列表")

    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = " id  id name 名称 categoryId 分类id "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getCirclesList(){
        ReqResponse<List<Record>> r=new ReqResponse();    ;

        r.setData(mediaService.getCirclesList());
        renderJson(r);
    }*/
       @ApiOperation(url = "/v1/mediaAdv/getCategoryCirclesList", tag = "mediaAdv", httpMethod = "post",description = "获取分类页圈子列表")
    @Params({
            @Param(name = "categoryId", description = "分类id", required = true, dataType = "string"),
            @Param(name = "pageNumber", description = "页码", required = true, dataType = "string"),
            @Param(name = "sortId", description = "排序字段 默认 成员最多 user_count  最新创建 create_date ", required = false, dataType = "string"),
            @Param(name = "sortValue", description = "排序值 asc 升 desc 降 ", required = false, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = " circleId 圈子id  name 圈子名称 coverImgWidth封面宽 coverImgHeight封面高 coverImgSrc 封面图片 uid 用户id,headImg头像 ,uName 用户名称 userCount 圈子人数"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getCategoryCirclesList(){
        String categoryId=getPara("categoryId");
           int pageNumber=getParaToInt("pageNumber");
           String sortId=getPara("sortId");
           String sortValue=getPara("sortValue");
           if(StrKit.isBlank(sortId)){
               sortId="user_count";
           }
           if(StrKit.isBlank(sortValue)){
               sortValue="desc";
           }
        ReqResponse<Page<Record>> r=new ReqResponse();    ;

        r.setData(mediaService.getCategoryCirclesList(categoryId,pageNumber,sortId,sortValue));
        renderJson(r);
    }

    @ApiOperation(url = "/v1/mediaAdv/getCategoryCarouselList", tag = "mediaAdv", httpMethod = "post",description = "获取分类页轮播图列表")
    @Params({
            @Param(name = "categoryId", description = "分类id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "{ imgSrc 图片地址 ,imgLinks 图片链接 imgRank 图片排序  id 视频广告id carouselId 轮播图id}"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getCategoryCarouselList(){
        String categoryId=getPara("categoryId");
        ReqResponse<List<Record>> r=new ReqResponse();
        r.setData(mediaService.getCategoryCarouselList(categoryId));
        renderJson(r);
    }



    @ApiOperation(url = "/v1/mediaAdv/getCategoryTop10List", tag = "mediaAdv", httpMethod = "post",description = "获取自媒体分类页top10列表")
    @Params({
            @Param(name = "categoryId", description = "分类id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "{ coverImgSrc 图片地址 ,title 标题 , praiseCount 点赞总数 ,  cityName 城市名称 , userId 用户id , id 视频id  }"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getCategoryTop10List(){
        String categoryId=getPara("categoryId");
        ReqResponse<List<Record>> r=new ReqResponse();
        List<Record>  record= mediaService.getCategoryTop10List(categoryId);
        r.setData(record);
        renderJson(r);
    }




    @ApiOperation(url = "/v1/mediaAdv/getCategoryHotAdvList", tag = "mediaAdv", httpMethod = "post",description = "获取自媒体分类页人气分页信息")
    @Params({
            @Param(name = "categoryId", description = "分类id", required = true, dataType = "string"),

            @Param(name = "pageNumber", description = "页码", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "totalRow 总行数  pageNumber第几页 firstPage 是否第一页 lastPage 是否最后一页 totalPage 总页数 pageSize每页条数  list[{   id 视频id coverImgSrc 图片地址   title 标题    praiseCount 点赞数 rewardCount 奖励数  cityName 城市名称 advType 1数据 2 广告 vedioLength 视频长度 type 类型  1自媒体 2企业广告3城市广告4传统文化  }]"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getCategoryHotAdvList(){
        String categoryId=getPara("categoryId");
        int pageNumber=getParaToInt("pageNumber");
        ReqResponse<Page<Record>> r=new ReqResponse();
        Page<Record> record= mediaService.getCategoryHotAdvList(pageNumber,categoryId);
        r.setData(record);
        renderJson(r);
    }
    @ApiOperation(url = "/v1/mediaAdv/getCategoryNearbyAdvList", tag = "mediaAdv", httpMethod = "post",description = "获取自媒体分类页附近分页信息")
    @Params({
            @Param(name = "categoryId", description = "分类id", required = true, dataType = "string"),
            @Param(name = "latitude", description = "纬度", required = true, dataType = "string"),
            @Param(name = "longitude", description = "经度", required = true, dataType = "string"),
            @Param(name = "pageNumber", description = "页码", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "totalRow 总行数  pageNumber第几页 firstPage 是否第一页 lastPage 是否最后一页 totalPage 总页数 pageSize每页条数  list[{id 视频id coverImgSrc 图片地址   title 标题   praiseCount 点赞数 rewardCount 奖励数    distance 距离  advType 1数据 2 广告 vedioLength 视频长度 type 类型  1自媒体 2企业广告3城市广告4传统文化}]"),

                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getCategoryNearbyAdvList(){
        String categoryId=getPara("categoryId");
        double latitude=Double.parseDouble(getPara("latitude"));
        double longitude=Double.parseDouble(getPara("longitude"));
        int pageNumber=getParaToInt("pageNumber");
        ReqResponse<Page<Record>> r=new ReqResponse();

        Page<Record> record= mediaService.getCategoryNearbyAdvList(latitude,longitude,pageNumber,categoryId);
        r.setData(record);
        renderJson(r);
    }
    @ApiOperation(url = "/v1/mediaAdv/getCategoryQueryList", tag = "mediaAdv", httpMethod = "post",description = "获取自媒体分类页查询列表")
    @Params({
            @Param(name = "categoryId", description = "分类id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "{ name 名称 style 布局样式(1普通布局2地区布局3购物分类4游戏分类5招聘6美食)  queryStyle 查询布局(1普通查询2职位搜索3美食4地区)  query 查询接口  }"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getCategoryQueryList(){
        String categoryId=getPara("categoryId");
        ReqResponse<List<Record>> r=new ReqResponse();
        List<Record>  record= mediaService.getCategoryQueryList(categoryId);
        r.setData(record);
        renderJson(r);
    }

    @ApiOperation(url = "/v1/mediaAdv/getCategoryOrdinaryList", tag = "mediaAdv", httpMethod = "post",description = "获取自媒体普通分类列表")
    @Params({
            @Param(name = "categoryId", description = "分类id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "{ categoryId 分类id   name 名称  imgSrc 图片  }"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getCategoryOrdinaryList(){
        String categoryId=getPara("categoryId");
        ReqResponse<List<Record>> r=new ReqResponse();
        List<Record>  record= mediaService.getCategoryOrdinaryList(categoryId);
        r.setData(record);
        renderJson(r);
    }



    @ApiOperation(url = "/v1/mediaAdv/getInfoMediaAdvCommentList", tag = "mediaAdv", httpMethod = "post",description = "获取自媒体评论信")
    @Params({
            @Param(name = "id", description = "视频id", required = true, dataType = "string"),
            @Param(name = "loginUid", description = "当前登录用户id", required = true, dataType = "string"),
            @Param(name = "pageNumber", description = "页码", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  totalRow 总行数  pageNumber第几页 firstPage 是否第一页 lastPage 是否最后一页 totalPage 总页数 pageSize每页条数  list[{id 记录id userId 评论用户 uName 评论用户名称 headImg 评论用户头像 content 内容 replyUserId 回复id rName回复用户名称 rheadImg回复用户头像 createDate 创建时间 commentId 回复评论id }] "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getInfoMediaAdvCommentList(){
        String id=getPara("id");
        int pageNumber=getParaToInt("pageNumber");
        ReqResponse<Page<Record>> r=new ReqResponse();
        AdvService advService=new AdvService();
        Page<Record> record= advService.getAdvCommentsById(id,pageNumber);
        r.setData(record);
        renderJson(r);
    }





    @ApiOperation(url = "/v1/mediaAdv/getMediaAdvAdvById", tag = "mediaAdv", httpMethod = "post",description = "获取自媒体广告视频信息")
    @Params({
            @Param(name = "loginUid", description = "当前登录用户id", required = true, dataType = "string"),
            @Param(name = "id", description = "视频id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  {  rewardCount 奖励总数 praiseCount 点赞总数 commentCount 评论数 cityName 城市名称 collectionCount 收藏总数 collectionState 已经收藏 1   没收藏 0 praiseState 已经点赞 1  没点赞 0  uid 用户id uName  用户名称 headImg 用户头像  coverImgSrc 图片地址   imgSrc 视频地址 ,  title 标题 imgNote 副标题  type 类型  1自媒体 2企业广告3城市广告4传统文化  createDate 创建时间  } "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getMediaAdvAdvById(){
        String id=getPara("id");
        ReqResponse<Record> r=new ReqResponse();
        String loginUid=getPara("loginUid");
        Record record= mediaService.getAdvById(id,loginUid);

        if(null!=record){

            r.setData(record);
        }
        else{
            r.setCode(1);
            r.setMsg("内容已下线或者不存在");
        }

        renderJson(r);
    }




    @ApiOperation(url = "/v1/mediaAdv/collection", tag = "mediaAdv", httpMethod = "post",description = "通过用户id   视频id  state收藏状态 1收藏0取消收藏")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "state", description = "收藏状态 1收藏0取消收藏", required = true, dataType = "string"),
            @Param(name = "id", description = "视频id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="data",description = " 总收藏数"),
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })

    public void collection(){
        EnterpriseAdvService enterpriseAdvService2 = enhance(EnterpriseAdvService.class);
        String loginUid=getPara("loginUid");
        String id=getPara("id");
        String state=getPara("state");
        ReqResponse<String> r=new ReqResponse();
        try {
           r.setData(enterpriseAdvService2.collection(loginUid,id,state));

        }catch (Exception e){
            e.printStackTrace();
            r.setCode(1);
            r.setMsg("操作失败");
        }
        renderJson(r);
    }

    @ApiOperation(url = "/v1/mediaAdv/praise", tag = "mediaAdv", httpMethod = "post",description = "通过用户id   视频id  state点赞状态 1点赞0取消点赞")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "state", description = "点赞状态 1点赞0取消点赞", required = true, dataType = "string"),
            @Param(name = "id", description = "视频id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="data",description = " 总点赞数"),
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })

    public void praise(){
        EnterpriseAdvService enterpriseAdvService2 = enhance(EnterpriseAdvService.class);
        String loginUid=getPara("loginUid");
        String id=getPara("id");
        String state=getPara("state");
        ReqResponse<String> r=new ReqResponse();
        try {
            r.setData(enterpriseAdvService2.praise(loginUid,id,state));

        }catch (Exception e){
            e.printStackTrace();
            r.setCode(1);
            r.setMsg("操作失败");
        }
        renderJson(r);
    }
    @ApiOperation(url = "/v1/mediaAdv/endPlayMediaAdvById", tag = "mediaAdv", httpMethod = "post",description = "播放完成给用户的积分")
    @Params({
            @Param(name = "id", description = "视频id", required = true, dataType = "string"),
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),

    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = " integral 得到积分 "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void endPlayMediaAdvById(){
        AdvService advService2 = enhance(AdvService.class);
        String loginUid=getPara("loginUid");
        String id=getPara("id");
        ReqResponse<Record> r=new ReqResponse();
        try {
            Record record = advService2.endPlayMediaAdvById(loginUid, id);

            r.setData(record);
        }catch (Exception e){
            r.setCode(1);

        }
        renderJson(r);
    }
}
